﻿// Jinx AJAX Framework
// Copyright (C) 2008 Blake Hegerle
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Formality.FormalSystem.Parser;

namespace Formality.FormalSystem
{
    using Stringer = Func<Proposition, Proposition, StringingStyle, string>;
    
    public static class Construction
    {
        public static Proposition Function(this string Name, IEnumerable<Variable> Arguments)
        {
            return new Proposition(Name, Arguments);
        }

        public static Proposition Function(this string Name, params Variable[] Arguments)
        {
            return new Proposition(Name, Arguments);
        }

        public static Proposition Binder(this string Operator, Variable Variable, IEnumerable<Proposition> Scopes)
        {
            return new Proposition(Operator, Variable, Scopes);
        }

        public static Proposition Binder(this string Operator, Variable Variable, params Proposition[] Scopes)
        {
            return new Proposition(Operator, Variable, Scopes);
        }

        public static Proposition Operator(this string OperatorString, IEnumerable<Proposition> Operands)
        {
            var Precedence = PropositionParser.Instance.PrecedenceRules;

            Stringer Stringer = Stringers.PrefixStringer;

            if (Precedence.TryGetOperator(OperatorString) != null)
                Stringer = Stringers.InfixStringer;

            return new Proposition(OperatorString, Operands, Stringer);
        }

        public static Proposition Operator(this string Operator, params Proposition[] Operands)
        {
            return Operator.Operator(Operands as IEnumerable<Proposition>);
        }
    }
}
